﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CSP.Dao.CommonDao;
using CSP.Dao.IObjectDaos.CSP;
using CSP.DataAccess;
using CSP.Model.CSP;

namespace CSP.Dao.ObjectDaos.CSP
{
    public class DomainTypeDao : CSPCommonDao, IDomainTypeDao
    {
        public DomainTypeDao(CSPContext context, bool isTransaction = false)
            : base(context, isTransaction)
        { }

        public ICollection<Model.CSP.DomainType> FindAll()
        {
            return _context.DomainTypes.ToArray();
        }

        public Model.CSP.DomainType GetDataById(int id)
        {
            return _context.DomainTypes.FirstOrDefault(a => a.Id == id);
        }

        public ICollection<Model.CSP.DomainType> GeDatatByIds(int[] Ids)
        {
            return _context.DomainTypes.Where(a => Ids.Contains(a.Id)).ToArray();
        }

        public void Add(Model.CSP.DomainType obj)
        {
            _context.DomainTypes.Add(obj);
            _context.SaveChanges();
        }

        public void Update(Model.CSP.DomainType obj)
        {
            DomainType domainType = GetDataById(obj.Id);
            if (domainType != null)
            {
                domainType = obj;
            }
            _context.SaveChanges();
        }

        public DomainType DeleteById(int id)
        {
            DomainType domainType = GetDataById(id);
            _context.DomainTypes.Remove(domainType);
            _context.SaveChanges();
            return domainType;
        }
    }
}
